% Name: grating.m
% Created 28/10/2011
% Crown Copyright
%
% Description: creates a binary grating of integer width and height.
%               
% @author Kevin O'Holleran <kevin.o-holleran@npl.co.uk>
%
% @param width integer
% @param height integer
% @param a angle of grating w.r.t x-axis in radians
% @param p period of the grating in pixels
% @param phase phase offset of the grating
% @return grating a matrix of size (width,height)
function [ grating ] = grating(width, height, a,period,phase,ratio)
    offset = period*phase/(2*pi);
    [x,y] = meshgrid(0:(width-1),0:(height-1));
    r = x.*cos(a)-y.*sin(a)+offset;
    r = r/period;
    m = mod(r,1);
    grating = m >= ratio;
end

